

// Time:  O(n)
// Space: O(1)


#include <iostream>
#include <string>
#include <vector>
#include <cassert>
using namespace std;
class Solution {
public:
    bool isPrefixString(string s, vector<string>& words) {
        int i = 0;
        for (const auto& word : words) {
            for (const auto& c : word) {
                if (i == s.size() || s[i] != c) {
                    return false;
                }
                ++i;
            }
            if (i == s.size()) {
                return true;
            }
        }
        return false;
    }
};

// Test case
int main() {
    Solution sol;

    // Test case 1
    string s1 = "iloveleetcode";
    vector<string> words1 = {"i", "love", "leetcode", "apples"};
    bool expected1 = true;
    bool result1 = sol.isPrefixString(s1, words1);
    assert(result1 == expected1);
    cout << "Test case 1 passed!" << endl;

    // Test case 2
    string s2 = "iloveleetcode";
    vector<string> words2 = {"apples", "i", "love", "leetcode"};
    bool expected2 = false;
    bool result2 = sol.isPrefixString(s2, words2);
    assert(result2 == expected2);
    cout << "Test case 2 passed!" << endl;

    // Test case 3
    string s3 = "ilove";
    vector<string> words3 = {"i", "love", "leetcode"};
    bool expected3 = true;
    bool result3 = sol.isPrefixString(s3, words3);
    assert(result3 == expected3);
    cout << "Test case 3 passed!" << endl;

    // Test case 4
    string s4 = "ilovecoding";
    vector<string> words4 = {"i", "love", "leetcode"};
    bool expected4 = false;
    bool result4 = sol.isPrefixString(s4, words4);
    assert(result4 == expected4);
    cout << "Test case 4 passed!" << endl;

    return 0;
}